package cn.wp.basic.controller;

import cn.wp.basic.service.IVerificationCodeService;
import cn.wp.basic.util.AjaxResult;
import cn.wp.user.domain.User;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
@RequestMapping("/verification")
public class VerificationCodeController {

    @Autowired
    private IVerificationCodeService verificationCodeService;

    /**
     * 门户网站 手机注册发送的验证码
     * @param user
     * @return
     */
    @PostMapping("/sendMobileCode")
    public AjaxResult sendMobileCode(@RequestBody User user){
        try {
            verificationCodeService.sendUserRegMobileCode(user.getPhone());
            return AjaxResult.me();
        } catch (Exception e) {
            e.printStackTrace();
            return AjaxResult.me().setSuccess(false).setMsg(e.getMessage());
        }

    }

    /**
     * 手机号和微信进行保定发送的验证码
     * @param user
     * @return
     */
    @PostMapping("/sendBinderMobileCode")
    public AjaxResult sendBinderMonileCode(@RequestBody User user){
        try {
            verificationCodeService.sendBinderMobileCode(user.getPhone());
            return AjaxResult.me();
        } catch (Exception e) {
            e.printStackTrace();
            return AjaxResult.me().setSuccess(false).setMsg(e.getMessage());
        }

    }

}
